package com.tbs.parkingsaleapp.UI.UpdateLike;

import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.tbs.parkingsaleapp.Http.AsycHttp;
import com.tbs.parkingsaleapp.Http.JsonData.LikeInfo;
import com.tbs.parkingsaleapp.Http.Listenner.UpdateLikeHttper;
import com.tbs.parkingsaleapp.R;
import com.tbs.parkingsaleapp.SystemManager.SystemDataMananger;

public class UpdateLikeActivity extends AppCompatActivity implements View.OnClickListener {

    public static final int UPDATED=1000;
    public static final String UPDATEKEY="like";
    LikeInfo info=new LikeInfo();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_like);
    }

    @Override
    public void onClick(View view) {
        int k= Integer.valueOf(view.getTag().toString());
        if(k<0)
        {
            if(SystemDataMananger.isLogined())
            {
                UpdateLikeHttper httper=new UpdateLikeHttper(this);
                AsycHttp<String ,Integer> http=new AsycHttp<>();
                http.setBackgroundAction(httper);
                http.setResultAction(httper).setContext(view.getContext());
                http.execute(SystemDataMananger.getLogined().getUserinfo().getId(),String.valueOf(LikeInfo.TraitToInt(info)));
            }
            else
            {
                Toast.makeText(this, "您没有登录，无法提交喜好", Toast.LENGTH_SHORT).show();
            }

        }
        else
        info.setLikes(k,((Switch)view).isChecked());
    }
}